<script>
function Del_Info(str){
	var q=confirm('Bạn có chắc chắn muốn xóa hay không?');	
	if(q==true) 
		window.location=str;
	
}
</script>
<?php
$sql="SELECT substr( QUYEN,8,1 ) as mq
FROM qldl_tai_khoan
WHERE ten_dang_nhap = '".$_SESSION['username']."'";
	$query = @mysql_query($sql,$conn);
	$row = @mysql_fetch_array($query);
	if($row['mq']==1){
	 @header('Location: index.php?page=km'); 
	}
	else {
	echo  "<script>alert ('Bạn không có quyền truy cập trang này!')</script>"; 
	echo "<meta http-equiv='refresh' content='0;url= index.php'>";
	}
?>
  <?php
			
			$sql="select max( MA_KHUYEN_MAI) from  qldl_khuyen_mai"; 
			$result=mysql_query($sql); 
			$kq=mysql_fetch_array($result); 
			$ma=$kq[0]+1; 
				?>
<div class="cpanel-right-tttk">
  <div id="panel-sliders" class="pane-sliders">
    <div class="panel">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" style=" padding:10px;">
        <thead>
        <tr style=" padding-bottom:10px;">
        <th colspan="3" align="left" style="padding-bottom:10px;">QUẢN LÍ KHUYẾN MÃI</th>
        </tr> 
        </thead>
        
        <tr valign="top" style="padding:5px;">
          <td width="54%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
            <table width="100%" border="1" bordercolor="#666666" class="adminlist_tt">
              <thead>
                <tr>
                  <th colspan="2"> Thêm mức khuyến mãi mới</th>
                </tr>
              </thead>
              <tbody>
                <form action="" method="post" enctype="multipart/form-data">
             
                <tr>
                  <td>Tiêu đề</td>
                  <td><input type="text" name="txt_tdkm" id="txt_tdkm" width="180px" /></td>
                  </tr>
                <tr>
                  <td>Nội dung</td>
                  <td><textarea name="area_km" id="area_km" style="height:100px; width:100%;"></textarea></td>
                  </tr>
                <tr>
                  <td colspan="2"><input type="submit" name="btn_add_km" id="btn_add_km" value="Lưu" />
                    <input type="reset" name="btn_huy_km" id="btn_huy_km" value="Hủy"  />
                    
                    <?php
				  if(isset($_POST['btn_add_km'])){
					$makm = $_POST['txt_mskm'];
					$tdkm = $_POST['txt_tdkm'];
					$ndkm = $_POST['area_km'];
				  
				
					
					 $sql = "INSERT INTO qldl_khuyen_mai VALUES('$ma','$tdkm','$ndkm')";
	  				$query = @mysql_query($sql,$conn);
						if($query)echo "<script>alert ('Thêm thông tin thành công.')</script>";	
						else echo "<script>alert ('Thêm không thành công!')</script>";
				
				  
	}
	  ?>
                    </td>
                </tr>
                </form>
              </tbody>
            </table>
          </div></td>
          <td width="0%">&nbsp;</td>
          <td width="46%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left" >
            <table width="100%" border="1" bordercolor="#666666" class="adminlist_tt" >
              <thead>
                <tr>
                  <th colspan="3"> Danh mục khuyến mãi</th>
                
                </tr>
              </thead>
              <tbody>
                <form action="" method="post" name="form_view" id="form_view">
                <tr>
                  
                  <td width="67">Mã số</td>
                  <td width="236">Tiêu đề</td>
                  <td width="130">Cập nhật</td>
                </tr>
                <?php
				$stt=0;
	$sql="select * from qldl_khuyen_mai";
	$query = @mysql_query($sql,$conn);	
	if(!$query) echo "Query error to display.";
	else while($row = @mysql_fetch_array($query)){
		$stt++;
			?>	 
                <tr>
                  
                  <td><?php echo $row['MA_KHUYEN_MAI'];?></td>
                  <td><?php echo $row['TIEU_DE'];?></td>
                  <td><a href="index.php?page=id_edit_km&amp;id_edit_km=<?php echo $row['MA_KHUYEN_MAI'];?>">Sửa</a> ||
                   <a onclick="Del_Info('index.php?page=km&amp;id_del_km=<?php echo $row['MA_KHUYEN_MAI']; ?>');" href="#">Xóa</a></td>
                </tr>
                <?php } ?>
                </form>
              </tbody>
            </table>
          </div></td>
        </tr>
      </table>
    </div>
  </div>
</div>
